package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Employee;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "员工管理")
@RestController
@RequestMapping("/api/employee")
public class EmployeeController {

    @Resource
    private EmployeeService employeeService;

    @ApiOperation("查询员工")
    @GetMapping("/")
    @SystemControllerLog(description = "查询员工", actionType = ActionTypeEnum.QUERY)
    public List<Employee> findAll(String name) {
        return employeeService.findAll(name);
    }

    @ApiOperation("根据id查询员工")
    @GetMapping("/{id}")
    @SystemControllerLog(description = "根据id查询员工", actionType = ActionTypeEnum.QUERY)
    public Employee findById(@PathVariable Integer id) {
        return employeeService.findById(id);
    }

    @ApiOperation("添加员工")
    @PostMapping("/")
    @SystemControllerLog(description = "添加员工", actionType = ActionTypeEnum.CREATE)
    public RespBean save(@RequestBody Employee employee) {
        return employeeService.save(employee);
    }

    @ApiOperation("更新员工")
    @PutMapping("/")
    @SystemControllerLog(description = "更新员工", actionType = ActionTypeEnum.UPDATE)
    public RespBean update(@RequestBody Employee employee) {
        return employeeService.update(employee);
    }

    @ApiOperation("删除员工")
    @DeleteMapping("/{id}")
    @SystemControllerLog(description = "删除员工", actionType = ActionTypeEnum.DELETE)
    public RespBean delete(@PathVariable Integer id) {
        return employeeService.delete(id);
    }

    @ApiOperation("查询未分配仓库的员工")
    @GetMapping("/warehouse")
    @SystemControllerLog(description = "查询未分配仓库的员工", actionType = ActionTypeEnum.QUERY)
    public List<Employee> findByWarehouse() {
        return employeeService.findByWarehouse();
    }

}
